import Vue from 'vue';
import Router from 'vue-router';
import tool from '@/js/plugins/zry.plugins.tool.js';
import bus from '@/js/common/bus.js';
import ycx from './ycx.js';
//import md from './md.js';
Vue.use(Router);

let router = new Router({
	routes: [{
		path: '/',
		redirect: '/index'
	}, {
		path: '/index',
		name: 'index',
		meta: {
			title: '比价网',
			isLoading: true,
			isLogin: false
		},
		component: resolve => require(['@/page/index/index.vue'], resolve),
		children: [{
			path: 'price',
			name: 'price',
			meta: {
				title: '比价网',
				isLoading: true,
				isLogin: false
			},
			component: resolve => require(['@/page/price'], resolve),
			children: []
		}, {
			path: 'goods',
			name: 'goods',
			meta: {
				title: '比价网',
				isLoading: true,
				isLogin: false
			},
			component: resolve => require(['@/page/goods'], resolve),
			children: []
		}, {
			path: 'goodsDetail',
			name: 'goodsDetail',
			meta: {
				title: '比价网',
				isLoading: true,
				isLogin: false
			},
			component: resolve => require(['@/page/goods/detail'], resolve),
			children: []
		}, {
			path: 'publish',
			name: 'publish',
			meta: {
				title: '比价网',
				isLoading: true,
				isLogin: false
			},
			component: resolve => require(['@/page/publish/index'], resolve),
			children: []
		}]
	}, {
		path: '/center',
		name: 'center',
		component: resolve => require(['@/page/center/index'], resolve),
		children: [{
			path: 'userCenter',
			name: 'userCenter',
			component: resolve => require(['@/page/userCenter/index'], resolve),
			children: [{
				path: 'index',
				name: 'userCenterIndex',
				component: resolve => require(['@/page/userCenter/road'], resolve),
			},{
				path: 'goodAddress',
				name: 'goodAddress',
				component: resolve => require(['@/page/userCenter/goodAddress'], resolve),
			},{
				path: 'myOrder',
				name: 'myOrder',
				component: resolve => require(['@/page/userCenter/myOrder'], resolve),
			}]
		}]
	}],
	scrollBehavior(to, from, savedPosition) {
		return {
			x: 0,
			y: 0
		}
	}
});

//router.beforeEach((to, from, next) => {
//	if(to.query.token) {
//		tool.setToken(to.query.token);
//		bus.$emit('getUserInfo', null);
//	}
//	next();
//});
//
//router.afterEach((to, from) => {
//	if(to.meta.title) {
//		tool.changeHtmlTitle(to.meta.title);
//	}
//	if(to.meta.isLogin) { // 判断该路由是否需要登录权限	
//		if(!tool.getToken()) {
//			if(from.path == '/login') {
//				bus.$emit('replaceRouter', '/price');
//			} else {
//				bus.$emit('changeRouter', '/login');
//			}
//		}
//	}
//});

export default router;